/* function* 来定义生成器 */
/* yield和next和py用法类似 */
{
    // genertaor基本定义
    let tell = function* () {
        yield 'a';
        yield 'b';
        return 'c'
    };
    let k = tell();
    console.log(k.next());
    console.log(k.next());
    console.log(k.next());
    console.log(k.next());
}

{
    let obj = {};
    obj[Symbol.iterator] = function* () {
        yield 1;
        yield 2;
        yield 3;
    }

    for (let value of obj) {
        console.log('value', value);
    }
}

{
    let state = function* () {
        while (1) {
            yield 'A';
            yield 'B';
            yield 'C';
        }
    }
    let status = state();
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
}

/* 
// 新语法糖 async await, 等价于上面的生成器
{
    let state = async function () {
        while (1) {
            await 'A';
            await 'B';
            await 'C';
        }
    }
    let status = state();
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
    console.log(status.next());
} 
*/